Lets build graphs from functions. By graph, I don't mean graphic, by graph I mean the actual data structure.
For this purpose, imagine the following. I will grab a subset of a domain in R, namely D, for this subset I will create N equidistant samples, this samples are going to be the nodes of my graph. The nodes of my graph are going to be connected in the following way.
given
def build_domain(min_d: float, max_d: float, N: int): return np.linspace(min_d, max_d, N)
def closest(fx, D: np.ndarray) -> int: return np.argmin(np.abs(fx-D))
def build_graph(min_d: float, max_d: float, N: int, fn: Callable[[float], float]) -> nx.Graph:
D = build_domain(min_d, max_d, N)
G = nx.Graph()
for i, x in enumerate(D): G.add_node(i, x=x)
for i, x in enumerate(D):
if i == N-1: break
G.add_edge(i, closest(fn(x), D))
return G
with this setting